package semantic;

import syntaxtree.*;
import java.util.HashMap;
import java.util.Iterator;


public class Table {
	public HashMap<Identifier,Class> classes;
	
	public Table() {
		classes = new HashMap<Identifier,Class>();
	}
	
	public void put(Identifier i, Class c) {
		classes.put(i, c);
	}
	
	public Class get(Identifier i) {
		Iterator<Identifier> it = classes.keySet().iterator();
		while(it.hasNext()) {
			Identifier id = (Identifier)it.next();
			if(id.s.equals(i.s)) return classes.get(id);
		}
		return null;
	}
	
	
	public boolean contains(Identifier i) {
		Iterator<Identifier> it = classes.keySet().iterator();
		while(it.hasNext()) {
			Identifier id = (Identifier)it.next();
			if(id.s.equals(i.s)) return true;
		}
		return false;
	}
	
	public void print() {
		System.out.println("Table: ");
		Iterator<Identifier> it = classes.keySet().iterator();
		while(it.hasNext()) {
			Identifier id = (Identifier)it.next();
			this.get(id).print();
		}
	}
}
